<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/14
 * Time: 13:36
 *
 * @copyright: ©2024 永州 微聚商网络科技有限公司
 * @link: https://www.wEijuyunke.com
 */

namespace app\home\controller;

use app\common\model\Label;
use app\Request;

class  TabClass{
    public function tabList(Request $request){
        $param = $request->param();
        $where['status'] = 1;
        if (isset($param['type']) && !empty($param['type'])){
            $where['type'] = $param['type'];
        }
        if (isset($param['pid'])){
            $where['pid'] = $param['pid'];
        }
        $tabClassModel = new \app\common\model\TabClass();
        if (isset($param['top']) && !empty($param['top'])){
            $tabList = $tabClassModel->where('pid','>',0)->where($where)->order('sort','asc')->select()->toArray();
            $count  = $tabClassModel->where('pid','>',0)->where($where)->count();
        }else{
            $tabList = $tabClassModel->where($where)->order('sort','asc')->select()->toArray();
            $count  = $tabClassModel->where($where)->count();
        }
        return success('分类列表',['list' =>$tabList, 'count' =>$count]);
    }

    public function labelList(Request $request){
        $param = $request->param();
        $labelModel = new Label();
        $where = [];
        if (isset($param['type']) && !empty($param['type'])){
            $where['type'] = $param['type'];
        }
        if (isset($param['pid']) ){
            $where['pid'] = $param['pid'];
        }
        $tabList = $labelModel>where($where)/*-->limit($start,$limit)*/->select()->toArray();
        $count = $labelModel/*->where($where)*/->count();
        return success('标签列表',['list' =>$tabList,'count' => $count]);
    }


    public function addLabel(Request $request){
        $param = $request->param();
        $data = [
            'name' => $param['name'],
            'create_time' =>  time(),
            'pid' => $param['pid'],
            'type' => $param['type'],
        ];

        $tabClassModel = new Label();
        $tabClassModel->insert($data);
        return success('添加成功');
    }



}
